package gitee.derumin.lifeissohard.mixin;

import gitee.derumin.lifeissohard.lishhungersystem.LishHungerManager;
import net.minecraft.advancement.criterion.ConsumeItemCriterion;
import net.minecraft.item.ItemStack;
import net.minecraft.item.MilkBucketItem;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(MilkBucketItem.class)
public abstract class MilkBucketItemMixin {

    @Redirect(method = "finishUsing" , at = @At(value = "INVOKE" , target = "Lnet/minecraft/advancement/criterion/ConsumeItemCriterion;trigger(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/item/ItemStack;)V"))
    private void playerDrinkMilk(ConsumeItemCriterion instance, ServerPlayerEntity player, ItemStack stack){
        instance.trigger(player,stack);
        if (player.getHungerManager() instanceof LishHungerManager lishHungerManager){
            lishHungerManager.drink("milk_in_bucket");
            lishHungerManager.removeHeavyMetal(1200d);
        }
    }
}
